'use strict';

const BaseController = require('./base');

class AdvantageController extends BaseController {
  get _service() {
    return 'advantage';
  }

  async create() {
    const { ctx } = this;
    const { name } = ctx.params();
    const result = await this._getService().create({ name });
    if (result) {
      this.success();
    } else {
      this.error('创建特点失败');
    }
  }

  async update() {
    const { ctx } = this;
    const { name } = ctx.params();
    const { id } = ctx.params;
    const result = await this._getService().update({ name, id });
    if (result) {
      this.success();
    } else {
      this.error('更新特点失败');
    }
  }

  async destroy() {
    await this._destory('删除特点失败');
  }

  async show() {
    await this._show('获取特点失败');
  }

  async index() {
    const { ctx } = this;
    const { name, prop, sort, pageIndex, pageSize } = ctx.params();
    const { createdAt } = ctx.queries;
    const result = await this._getService().findList({ name, prop, sort, pageIndex, pageSize, createdAt });
    if (result) {
      this.success(result.data, result.count);
    } else {
      this.error('获取特点失败');
    }
  }

  async all() {
    await this._all('获取特点失败');
  }
}

module.exports = AdvantageController;
